<template>
   <div>
       <!-- 顶部导航滑动 -->
        <div id="slider" class="mui-slider ">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item',item.id == 0 ? 'mui-active':'']" v-for="item in cates" :key="item.id" data-wid="tab-top-subpage-1.html" @click="getImages(item.id)">
                        {{item.title}}
                    </a>
                </div>
            </div>
        </div>
        <!-- 图片列表区域 -->
        <ul id="photolist">
        <router-link v-for="item in list" :key="item.id" :to="'/home/photoinfo/'+item.id" tag="li">
            <img v-lazy="item.img_url">
            <div class="info">
                <h1 class="info-title">
                    {{item.title}}
                </h1>
                <div class="info-body">
                    {{item.zhaiyao}}
                </div>
            </div>
        </router-link>
        </ul>
    </div> 
</template>
<script>
import mui from '@/lib/mui/js/mui.min.js'
export default {
    data(){
        return{
            cates:[],
            list:[]
        }
    },
    mounted(){ 
        mui('.mui-scroll-wrapper').scroll({
	        deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });
    },
    created(){
        this.getAllCategory(),
        this.getImages(0)
    },
    methods:{
        async getAllCategory(){
            const {data} = await this.$http.get('api/getimgcategory')
            if(data.status === 0){
                data.message.unshift({title:'全部',id:0})
                this.cates = data.message
            }
        },
        async getImages(cateId){
            const {data} = await this.$http.get('api/getimages/'+cateId)
            if(data.status === 0){
                this.list = data.message
                this.list.forEach(e=>{
                    e.img_url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1538108387262&di=7a7631fa872b4b27d509917acb3d2c35&imgtype=0&src=http%3A%2F%2Flc-mqyvcsy3.cn-n1.lcfile.com%2F1b6ae28a2e5f66c9.jpg'
                })
            }
        }
    }
}
</script>
<style lang="scss" scoped>
* {
  touch-action: pan-y;
}
#photolist{
    list-style: none;
    margin: 0;
    padding: 10px;
    padding-bottom: 0;
    li{
        background-color: #ccc;
        margin-bottom: 10px;
        box-shadow: 0 0 9px #999;
        position: relative;
        img{
            width: 100%;
            vertical-align: middle;
        }
        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: auto;
        }
        .info{
            color:#fff;
            position: absolute;
            bottom: 0;
            background-color: rgba($color: #000000, $alpha: 0.4);
            max-height: 84px;

            .info-title{
                font-size: 14px;
            }
            .info-body{
                font-size: 13px;
            }
        }
    }
}

</style>
